package edu.cque.jt.common.thread;

/**
 * @author Hua
 * @create 2022-07-22 23:44
 */
public class Singleton {
    private Singleton() {
    }

    ;
    private static Singleton instance;

    public static Singleton getInstance() {//单例设计,双重校验
        if (instance == null) {
            synchronized (Singleton.class) {
                if (instance == null)
                    instance = new Singleton();
            }
        }
        return instance;
    }

    public static void main(String[] args) {
        new Thread(() -> System.out.println(getInstance())).start();
        new Thread(() -> System.out.println(getInstance())).start();
        new Thread(() -> System.out.println(getInstance())).start();
    }
}



